import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meco/views/index.dart';

import 'widgets/bottom_nav_bar.dart';

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage>
    with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return const _MainViewGetX();
  }
}

class _MainViewGetX extends GetView<MainController> {
  const _MainViewGetX();

  // 主视图
  Widget _buildView() {
    return PageView(
      controller: controller.pageController,
      physics: const NeverScrollableScrollPhysics(), // 禁止滑动切换
      children: [
        const HomePage(),
        const TimePage(),
        const SharePage(),
        const MePage(),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MainController>(
      id: "main",
      builder: (_) {
        return Scaffold(
          body: _buildView(),
          bottomNavigationBar: BottomNavBar(controller: controller),
          extendBody: true, // 让内容区域延伸到底部导航栏下面
        );
      },
    );
  }
}
